home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / glibmm-2.4 / glibmm / helperlist.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-04-20  |  3.9 KB  |  166 lines

  1. // -*- c++ -*-
  2. #ifndef _GLIBMM_HELPERLIST_H
  3. #define _GLIBMM_HELPERLIST_H
  4. /* $Id: helperlist.h,v 1.1.1.1 2003/01/07 16:58:46 murrayc Exp $ */
  5.  
  6. /* helperlist.h
  7.  *
  8.  * Copyright 2002 The gtkmm Development Team
  9.  *
  10.  * This library is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU Library General Public
  12.  * License as published by the Free Software Foundation; either
  13.  * version 2 of the License, or (at your option) any later version.
  14.  *
  15.  * This library is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18.  * Library General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU Library General Public
  21.  * License along with this library; if not, write to the Free
  22.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #include <glibmm/containers.h>
  26.  
  27. namespace Glib
  28. {
  29.  
  30. // This class has some pure virtual methods which need to be implemented by derived classes.
  31. template< typename T_Child, typename T_CppElement, typename T_Iterator >
  32. class HelperList
  33. {
  34. public:
  35.   HelperList()
  36.   : gparent_(0)
  37.   {}
  38.  
  39.   HelperList(GObject* gparent)
  40.   : gparent_(gparent)
  41.   {}
  42.  
  43.   virtual ~HelperList()
  44.   {}
  45.  
  46.   typedef T_Child value_type;
  47.   typedef value_type& reference;
  48.   typedef const value_type& const_reference;
  49.  
  50.   typedef T_Iterator iterator;
  51.   typedef List_ConstIterator<iterator> const_iterator;
  52.   typedef List_ReverseIterator<iterator> reverse_iterator;
  53.   typedef List_ConstIterator<reverse_iterator> const_reverse_iterator;
  54.  
  55.   typedef T_CppElement element_type;
  56.  
  57.   typedef size_t difference_type;
  58.   typedef size_t size_type;
  59.  
  60.   //These are implemented differently for each Helper List.
  61.   virtual iterator erase(iterator) = 0;
  62.  
  63.   virtual void erase(iterator start, iterator stop)
  64.   {
  65.     while(start != stop)
  66.       start = erase(start); //Implemented in derived class.
  67.   }
  68.  
  69.   virtual void remove(const_reference) = 0;
  70.  
  71.   size_type size() const
  72.   {
  73.     return g_list_length(glist());
  74.   }
  75.  
  76.   inline size_type max_size() { return size_type(-1); }
  77.   inline bool empty() { return glist() == 0; }
  78.  
  79.   inline iterator begin()
  80.     {return begin_();}
  81.   inline iterator end()
  82.     {return end_();}
  83.  
  84.   inline const_iterator begin() const
  85.     { return const_iterator(begin_()); }
  86.   inline const_iterator end() const
  87.     { return const_iterator(end_()); }
  88.  
  89.   inline reverse_iterator rbegin()
  90.     { return reverse_iterator(end_()); }
  91.   inline reverse_iterator rend()
  92.     { return reverse_iterator(begin_()); }
  93.  
  94.   inline const_reverse_iterator rbegin() const
  95.     { return const_reverse_iterator(reverse_iterator(end_())); }
  96.   inline const_reverse_iterator rend() const
  97.     { return const_reverse_iterator(reverse_iterator(begin_())); }
  98.  
  99.   reference front() const
  100.   {
  101.     return *begin();
  102.   }
  103.  
  104.   reference back() const
  105.   {
  106.     return *(--end());
  107.   }
  108.  
  109.   reference operator[](size_type l) const
  110.   {
  111.     size_type j = 0;
  112.     iterator i;
  113.     for(i = begin(), j = 0; i != end(), j < l; ++i, ++j);
  114.     return (*i);
  115.   }
  116.  
  117. //  iterator find(const_reference w)
  118. //  {
  119. //    iterator i = begin();
  120. //    for(i = begin(); i != end() && (*i != w); i++);
  121. //    return i;
  122. //  }
  123. //
  124. //  iterator find(Widget& w)
  125. //  {
  126. //    iterator i;
  127. //    for (i = begin(); i != end() && ((*i)->$1() != &w); i++);
  128. //    return i;
  129. //  }
  130.  
  131.   //Derived classes might choose to reimplement these as public:
  132.   inline void pop_front()
  133.     { erase(begin()); }
  134.   inline void pop_back()
  135.     { erase(--end()); }
  136.  
  137.   void clear()
  138.     { erase(begin(), end()); }
  139.  
  140.   GObject* gparent()
  141.     { return gparent_; };
  142.   const GObject* gparent() const
  143.     { return gparent_; };
  144.  
  145. protected:
  146.   virtual GList*& glist() const = 0;      // front of list
  147.  
  148.   iterator begin_() const
  149.   {
  150.     return iterator(glist(), glist());
  151.   }
  152.  
  153.   iterator end_() const
  154.   {
  155.     return iterator(glist(), (GList*)0);
  156.   }
  157.  
  158.   GObject* gparent_;
  159. };
  160.  
  161.  
  162. } /* namespace Glib */
  163.  
  164. #endif /* _GLIBMM_HELPERLIST_H */
  165.  
  166.